var channelId;

window.onload = function () {
    channelId = getQuery("id");
    getMain(1);
    add();
};

async function getMain(pageNo) {
    let main = await ajaxGet("/main/findByChannelId",{
        pageNo:pageNo,
        channelId: channelId,
        name:$("name").value,
        author:$("author").value,
        start:$("start").value,
        end: $("end").value
    });

    let str = "";
    for (let i = 0; i < main.list.length; i++) {
        let info = main.list[i];
        str += `<tr>
                    <td><a href="/html/reply.html?id=${info.mainId}">${info.mainName}</a></td>
                    <td>${info.userBean.username}</td>
                    <td>${info.num}</td>
                    <td>${info.mainTime}</td>
                </tr>`;
    }
    $("mainData").innerHTML = str;

    let cutStr = "";
    for (let i = 1; i <= main.pages; i++) {
        cutStr += `<a style="margin-left: 15px" href="javascript:getMain(${i})">${i}</a>`;
    }

    $("pageDiv").innerHTML = cutStr;
}

function add() {
    $("add").href = "/html/addMain.html?id="+channelId;
}